package org.example.cet.demos.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.example.cet.demos.converter.converter;
import org.example.cet.demos.domain.PageBean;
import org.example.cet.demos.domain.dto.ClassroomDto;
import org.example.cet.demos.domain.dto.StudentDto;
import org.example.cet.demos.domain.po.Classroom;
import org.example.cet.demos.domain.po.Student;
import org.example.cet.demos.domain.query.ClassroomQuery;
import org.example.cet.demos.mapper.ClassroomMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.cet.demos.service.IClassroomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hq
 * @since 2024-12-18
 */
@Service
@RequiredArgsConstructor
public class ClassroomServiceImpl extends ServiceImpl<ClassroomMapper, Classroom> implements IClassroomService {
    private final converter converter;

    @Override
    public PageBean getPage(ClassroomQuery classroomQuery){
        Page<Classroom> page=new Page<>(classroomQuery.getCurrentPage(), classroomQuery.getPageSize());
        lambdaQuery().like(Classroom::getId,classroomQuery.getId())
                .like(!StrUtil.isBlankIfStr(classroomQuery.getName()),Classroom::getName,classroomQuery.getName())
                .eq(classroomQuery.getTeachId() != null, Classroom::getTeachId, classroomQuery.getTeachId())
                .like(classroomQuery.getPeopleSum()!=null,Classroom::getPeopleSum,classroomQuery.getPeopleSum())
                .page(page);
        PageBean pageBean=new PageBean();
        pageBean.setTotal(page.getTotal());
        pageBean.setRows(page.getRecords());
        return pageBean;
    }

    @Autowired
    private ClassroomMapper classroomMapper;
    @Override
    public List<StudentDto> findStu(String id){
        return classroomMapper.findStu(id);
    }

    public List<ClassroomDto> getList(){
        return classroomMapper.getList();
    }
}
